<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>json 快速入门案例</title>
    <script type="text/javascript">

        window.onload = function () {
            /*
            老师解读
            1. myJson 就是一个json对象
            2. 演示如何获取到json对象的各个属性/key
             */
            var myJson = {
                "key1": "韩顺平教育",  // 字符串
                "key2": 123,    // Number
                "key3": [1, "hello", 2.3],  // 数组
                "key4": {"age": 12, "name": "jack"},  //json对象
                "key5": [      //json数组
                    {"k1": 10, "k2": "milan"},
                    {"k3": 30, "k4": "smith"},

                ]
            };

            //1. 取出key1
            console.log("key1= ", myJson.key1);
            //2. 取出key3
            console.log("key3= ", myJson.key3);
            //   可以对key3取出的值(Array), 遍历
            for (var i = 0; i < myJson.key3.length; i++) {
                console.log("第%i个元素的值= " , i, myJson.key3[i]);
            }
            //3. 取出key4
            console.log("key4= " , myJson.key4 , " name= " , myJson.key4.name);
            //4. 取出key5
            console.log("key5= " , myJson.key5, " k4= ", myJson.key5[1].k4)
        }

    </script>
</head>
<body>
<h1>json 快速入门案例</h1>
</body>
</html>